﻿Imports System.Data.SqlClient

Public Class clsInfonavit
    Private mintIdRegistro As Integer
    Private mintidEmpleado As Integer
    Private mdatFecha As Date
    Private mdecOriginal As Decimal
    Private mdecNuevo As Decimal
    Private mstrMotivo As String
    Private mstrCapturo As String
    Private mstrReportado As String
    Private mstrTipo As String
    Public Property idRegistro() As Integer
        Get
            Return mintIdRegistro
        End Get
        Set(ByVal value As Integer)
            mintIdRegistro = value
        End Set
    End Property

    Public Property idempleado() As Integer
        Get
            Return mintidEmpleado
        End Get
        Set(ByVal value As Integer)
            mintidEmpleado = value
        End Set
    End Property
    Public Property Fecha() As Date
        Get
            Return mdatFecha
        End Get
        Set(ByVal value As Date)
            mdatFecha = value
        End Set
    End Property
    Public Property Original() As Decimal
        Get
            Return mdecOriginal

        End Get
        Set(ByVal value As Decimal)
            mdecOriginal = value
        End Set
    End Property
    Public Property nuevo() As Decimal
        Get
            Return mdecNuevo

        End Get
        Set(ByVal value As Decimal)
            mdecNuevo = value

        End Set
    End Property

    Public Property Motivo() As String
        Get
            Return mstrMotivo
        End Get
        Set(ByVal value As String)
            mstrMotivo = value
        End Set
    End Property
    Public Property Capturo() As String
        Get
            Return mstrCapturo
        End Get
        Set(ByVal value As String)
            mstrCapturo = value
        End Set
    End Property
    Public Property Reportado() As String
        Get
            Return mstrReportado
        End Get
        Set(ByVal value As String)
            mstrReportado = value
        End Set
    End Property
    Public Property Tipo() As String
        Get
            Return mstrTipo
        End Get
        Set(ByVal value As String)
            mstrTipo = value
        End Set
    End Property
    Public Sub New()
        mintIdRegistro = 0
        mintidEmpleado = 0
        mdatFecha = Now()
        mstrMotivo = ""
        mstrCapturo = ""
        mstrReportado = ""
        mdecNuevo = 0
        mdecOriginal = 0
        mstrTipo = ""


    End Sub
    Public Sub Borrar()
        Call SetSqlCitra("Delete From InfonavitFonacot Where idRegistro = " & idRegistro)

    End Sub
    Public Sub Buscar()
        Dim cnConn As New SqlConnection
        cnConn.ConnectionString = CitraConnection

        Dim cmdBuscar As New SqlCommand
        cmdBuscar.Connection = cnConn
        cmdBuscar.CommandText = "SELECT * From InfonavitFonacot " & _
        " WHERE idRegistro=" & idRegistro

        Dim rdBuscar As SqlDataReader

        cnConn.Open()
        rdBuscar = cmdBuscar.ExecuteReader

        If rdBuscar.Read() Then
            mintIdRegistro = rdBuscar("idRegistro")
            mintidEmpleado = rdBuscar("idempleado")
            mdatFecha = rdBuscar("fecha")
            mstrMotivo = rdBuscar("motivo").ToString.Trim
            mstrCapturo = rdBuscar("capturo").ToString.Trim
            mstrReportado = rdBuscar("reportado").ToString.Trim
            mdecOriginal = rdBuscar("original")
            mdecNuevo = rdBuscar("nuevo")
            mstrTipo = rdBuscar("Tipo").ToString.Trim
        Else
            mintIdRegistro = 0
            mintidEmpleado = 0
            mdatFecha = Now()
            mstrMotivo = ""
            mstrCapturo = ""
            mstrReportado = ""
            mdecNuevo = 0
            mdecOriginal = 0
            mstrTipo = ""

        End If

        rdBuscar.Close()
        cnConn.Close()


    End Sub
    Public Sub Insertar()
        Dim sql As String = "Insert Into InfonavitFonacot (" & _
                            "IdRegistro," & _
                            "IdEmpleado," & _
                            "Fecha," & _
                            "Original," & _
                            "Nuevo," & _
                            "Motivo," & _
                            "Capturo," & _
                            "Reportado," & _
                            "Tipo)" & _
                            "VALUES (" & _
                            "@IdRegistro," & _
                            "@IdEmpleado," & _
                            "@Fecha," & _
                            "@Original," & _
                            "@Nuevo," & _
                            "@Motivo," & _
                            "@Capturo," & _
                            "@Reportado," & _
                            "@Tipo)"


        Dim cnConn As New SqlConnection
        cnConn.ConnectionString = CitraConnection

        Dim Command As New SqlCommand(sql, cnConn)

        Command.Parameters.AddWithValue("IdRegistro", mintIdRegistro)
        Command.Parameters.AddWithValue("IdEmpleado", mintIdEmpleado)
        Command.Parameters.AddWithValue("Fecha", mdatFecha)
        Command.Parameters.AddWithValue("Original", mdecOriginal)
        Command.Parameters.AddWithValue("Nuevo", mdecNuevo)
        Command.Parameters.AddWithValue("Motivo", mstrMotivo)
        Command.Parameters.AddWithValue("Capturo", mstrCapturo)
        Command.Parameters.AddWithValue("Reportado", mstrReportado)
        Command.Parameters.AddWithValue("Tipo", mstrTipo)

        cnConn.Open()
        Dim RowsAffected As Integer = Command.ExecuteNonQuery

        If RowsAffected > 0 Then
            cnConn.Close()
        Else
            MsgBox("No fue posible insertar el registro ", MsgBoxStyle.Exclamation, "Aviso")
            If cnConn.State = ConnectionState.Open Then
                cnConn.Close()
            End If
        End If
    End Sub
End Class
